package saxion.speelveld.spaceengineer.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class TileDB extends SQLiteOpenHelper
{

	public static final String TABLE_NAME = "tileset";

	public static final String COLUMN_ID = "_id";

	public static final String COLUMN_GAMEID = "game_id";

	public static final String COLUMN_TILEROW = "tile_row";

	public static final String COLUMN_TILECOL = "tile_col";

	public static final String COLUMN_TILEBACKGROUNDID = "tile_backgroundid";

	public static final String COLUMN_RESOURCEORDINAL = "tile_resourceOrdinal";

	public static final String COLUMN_BUILDINGID = "tile_buildingid";

	public static final String COLUMN_INFRASTRUCTURECONNECTION = "tile_infrastructure";

	public static final String COLUMN_OBSTACLEID = "tile_obstacleid";

	private static final String DATABASE_FILENAME = "tiles.db";

	private static int DATABASE_VERSION = 1;

	public TileDB(Context context)
	{
		super(context, DATABASE_FILENAME, null, DATABASE_VERSION);
	}

	public TileDB(Context context, String name, CursorFactory factory,
		int version)
	{
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db)
	{
		db.execSQL("create table " + TABLE_NAME +
			"(" + COLUMN_ID + " integer primary key autoincrement, "
			+ COLUMN_GAMEID + " integer not null ,"
			+ COLUMN_TILEROW + " integer not null ,"
			+ COLUMN_TILECOL + " integer not null ,"
			+ COLUMN_TILEBACKGROUNDID + " integer ,"
			+ COLUMN_RESOURCEORDINAL + " integer ,"
			+ COLUMN_INFRASTRUCTURECONNECTION + " text , "
			+ COLUMN_BUILDINGID + " integer , "
			+ COLUMN_OBSTACLEID + " integer );");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
		onCreate(db);
	}

}
